<?php

$host = '127.0.0.1';
$port = 9501;

/**
 * 同步阻塞客户端
 * SWOOLE_SOCK_SYNC 同步阻塞模式  SWOOLE_SOCK_ASYNC 异步非阻塞模式
 */
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);

// 连接服务器
// 5 秒超时
$client->connect($host, $port, 5) or die("connect failed. Error: {$client->errCode}\n");

fwrite(STDOUT, "请输入消息：");
$msg = trim(fgets(STDIN));

// 发送数据
$client->send($msg) or die("send failed. Error: {$client->errCode}\n");

// 接收数据
echo $client->recv();

// 关闭连接
$client->close();